package main;

import com.google.gson.JsonObject;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;

/**
 *
 * @author xDrake
 */
public class Message {
    private int ID;
    private int userID;
    private String userLogin;
    private String text = "";
    private Timestamp time;
    
    public int getID() {
        return ID;
    }

    public String getUserLogin() {
        return userLogin;
    }

    public void setUserLogin(String userLogin) {
        this.userLogin = userLogin;
    }

    public Timestamp getTime() {
        return time;
    }

    public void setTime(Timestamp time) {
        this.time = time;
    }

    public void setID(int ID) {
        this.ID = ID;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public int getUserID() {
        return userID;
    }

    public void setUserID(int userID) {
        this.userID = userID;
    }

    @Override
    public String toString() {
        JsonObject obj = new JsonObject();
        obj.addProperty("ID", ID);
        obj.addProperty("userID", userID);
        obj.addProperty("userLogin", userLogin);
        obj.addProperty("text", text);
        
        SimpleDateFormat df = new SimpleDateFormat();
        String formattedDate = df.format(this.time);
        obj.addProperty("time", formattedDate);
        
        return obj.toString();
    }
    
    public String[] getArray(){
        SimpleDateFormat df = new SimpleDateFormat();
        String formattedDate = df.format(this.time);
        
        String [] arr = new String[5];
        arr[0] = String.valueOf(ID);
        arr[1] = String.valueOf(userID);
        arr[2] = userLogin;
        arr[3] = text;
        arr[4] = formattedDate;
        
        return arr;
    }
    public String getFormattedDate(){
//        SimpleDateFormat df = new SimpleDateFormat("k:m");
//        String formattedDate = df.format(this.time);     
//        return formattedDate;

        
        DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault());
        String str = df.format(this.time);
        return str;
    }

}
